# pyqt5组件项目
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
from component.demo import Demo

def exception_hook(exctype, value, traceback):
    """捕获未处理的异常"""
    print(exctype, value, traceback)
    sys.__excepthook__(exctype, value, traceback)
    sys.exit(1)

if __name__ == "__main__":
    # 设置异常钩子
    sys.excepthook = exception_hook
    
    print("启动应用...")
    app = QApplication(sys.argv)
    
    try:
        print("创建Demo窗口...")
        demo = Demo(app)
        
        # 显示一个消息框确认窗口已创建
        QMessageBox.information(None, "提示", "Demo窗口已创建，点击确定显示窗口")
        
        print("显示Demo窗口...")
        demo.show()
        
        # 确保窗口显示在前台
        demo.raise_()
        demo.activateWindow()
        
        print("进入事件循环...")
        sys.exit(app.exec_())
    except Exception as e:
        print(f"发生错误: {e}")
        QMessageBox.critical(None, "错误", f"程序发生错误: {e}")
        raise